'use strict';

const Controller = require('egg').Controller;

class RegisterController extends Controller {
  async index() {
    const { ctx } = this;
    console.log(ctx.request.body)
    var {username,pass} = ctx.request.body
    var db =  this.app.mongodb;
    var res =await db.collection("name").find({username}).toArray()
    if(res.length){
        ctx.body = {
            code:400,
            msg:"用户名已经被注册"
        }
    }else{
        var res =await db.collection("name").insertOne({username,pass})
        ctx.body = {
            code:200,
            msg:"注册成功"
        }
    }
  }
}

module.exports = RegisterController;
